import moment from 'moment';

const visitData = [];
const visitData2 = [];
const beginDay = new Date().getTime();

const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5];
const fakeY2 = [3, 6, 7, 8, 4, 5, 2, 7, 9, 5, 3, 5, 8, 3, 7, 3, 2];
for (let i = 0; i < fakeY.length; i += 1) {
  visitData.push({
    x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
    y: fakeY[i],
  });
}
for (let i = 0; i < fakeY2.length; i += 1) {
  visitData2.push({
    x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
    y: fakeY2[i],
  });
}

const bug = {
  bugTotal: 20293,
  bugNumWeekGrowth: 0.243,
  bugNumDayGrowth: -0.432,
  bugDayAverage: 80,
  bugMonthTotal: 312,
  bugMonthDetail: visitData,
  bugMonthMax: 120,
  bugHandUpScale: 0.093454353456,
  bugHandUpWeekGrowth: -0.1234,
  bugHandUpDayGrowth: 0.062,
  bugModel: [
    { projectName: '全部项目', data: [] },
    { projectName: 'mBlock', data: [] },
    { projectName: 'Makeblock', data: [] },
    { projectName: 'Nueron', data: [] },
    { projectName: 'Laser', data: [] },
    { projectName: 'mBlock app', data: [] },
    { projectName: 'mBlock Go', data: [] },
    { projectName: 'mBlock what', data: [] },
  ],
  bugProjectTotal: [
    { x: 'mBlock', y: 4544 },
    { x: 'Makeblock', y: 3321 },
    { x: 'Nueron', y: 3466 },
    { x: 'Laser', y: 2341 },
    { x: 'mBlock app', y: 1654 },
    { x: 'mBlock Go', y: 1231 },
    { x: 'switf', y: 954 },
    { x: '3D', y: 436 },
    { x: '其它', y: 2346 },
    { x: '阿萨德个', y: 2346 },
    { x: 'what', y: 345 },
    { x: 'why', y: 24 },
    { x: 'how', y: 456 },
    { x: 'hello', y: 154 },
    { x: 'world', y: 555 },
  ],
  bugProjectHandUp: [
    { projectName: 'mBlock', handingRate: '0.134' },
    { projectName: 'Makeblock', handingRate: '0.243' },
    { projectName: 'Nueron', handingRate: '0.025' },
    { projectName: 'Laser', handingRate: '0.065' },
    { projectName: 'switf', handingRate: '0.090' },
    { projectName: 'mBlock Go', handingRate: '0.072' },
    { projectName: '3D maker', handingRate: '0.056' },
  ],
  bugProjectTrend: [
    { projectName: 'mBlock', data: [] },
    { projectName: 'Makeblock', data: [] },
    { projectName: 'Nueron', data: [] },
    { projectName: 'Laser', data: [] },
    { projectName: 'switf', data: [] },
    { projectName: 'mBlock Go', data: [] },
    { projectName: '3D maker', data: [] },
  ],
};

const test = {
  testTotal: 999,
  testMonthDetail: visitData2,
  testSuccessScale: 0.58,
};

for (let i = 0; i < 50; i += 1) {
  for (let j in bug.bugModel) {
    bug.bugModel[j]['data'].push({
      index: i + 1,
      model: `model_${i}`,
      count: Math.floor(Math.random() * 10000),
      growth: 0.5 - Math.random(),
    });
  }
}
for (let j in bug.bugProjectTrend) {
  for (let i = 0; i < 20; i += 1) {
    bug.bugProjectTrend[j]['data'].push({
      x: new Date().getTime() + 1000 * 60 * 60 * 24 * i,
      y1: Math.floor(Math.random() * 100) + 10,
      y2: Math.floor(Math.random() * 100) + 10,
      y3: Math.floor(Math.random() * 100) + 10,
    });
  }
}

async function getTestData(ctx) {
  const result = {
    code: 0,
    message: '请求成功',
    data: {
      test
    },
  };
  ctx.body = result;
};

async function getJiraData(ctx) {
  const result = {
    code: 0,
    message: '请求成功',
    data: {
      ...bug
    },
  };
  ctx.body = result;
};

module.exports = {
  getTestData,
  getJiraData
}
